package cn.hbcj.servlet.web;

import cn.hbcj.servlet.dao.Impl.UserDaoImpl;
import cn.hbcj.servlet.dao.UserDao;
import cn.hbcj.servlet.domain.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

/**
 * Created by Administrator on 2020/3/21.
 */
@WebServlet("/LoginServlet")
public class LoginServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        //设置编码
//        request.setCharacterEncoding("utf-8");
//        //获取请求参数
//        String username = request.getParameter("username");
//        String password = request.getParameter("password");
//        //封装user对象
//        User loginuser=new User();
//        loginuser.setName(username);
//        loginuser.setPwd(password);
//
//        //调用UserDao的login方法
//        UserDao dao=new UserDaoImpl();
//        try {
//                User user=dao.login(loginuser);
//
//                if(user==null){
//                    request.getRequestDispatcher("/failServlet").forward(request,response);
//                }else{
//                    request.setAttribute("user",user);
//                    request.getRequestDispatcher("/successServlet").forward(request,response);
//                }
//
//        } catch (SQLException e) {
//            e.printStackTrace();
//        }


    }
}
